<?php
/**
 * @fileoverview    找回密码发送邮件
 * @author          zhanglei11
 * @date            
 * @copyright       sina meila
 */
include_once '../../__global.php';
include_once SERVER_ROOT_PATH.'/include/tool/ml_tool_sendMq.php';
include(SERVER_ROOT_PATH.'/include/config/dataRule/ml_datarule_user.php');

class aj_sendEmailToReset extends ml_controller{

    private $email;

    function main(){
        
        //    miss 获取用户信息
        $isExists = false;
        $oAccount = new ml_model_dbUserAccount();
        $rs = $oAccount->getAccountByEmail($this->email);
        $row = $oAccount->get_data();
//        $oAccount->isEmailExists($this->email,$isExists);
        
        if(!$rs) {  //  账号不存在
            $this->api_output(ML_RCODE_PARAM,array(),'您输入的邮箱尚未注册，请立即注册');
        }
        
        $obj = new ml_tool_securecode();
        $code = $obj->passport_encrypt($this->email);
        
        
        $url = SITE_ROOT_URL.'/page/user/setpwd.php?code='.$code;

        //投放队列
        ml_tool_sendMq::sendMail($this->email,ML_SMTP_TITLE,'findPwd',$url,$row['nickname']);        
    
        
        $this->api_output(ML_RCODE_SUCC);
    }

    function initParam() {
        
        $this->email = $this->input('email','P');    //目标用户
    }

    function checkParam() {
        $this->check_referer();
         //email 判断一下格式
        if(filter_var($this->email , FILTER_VALIDATE_EMAIL) == false)
            $this->api_output(ML_RCODE_PARAM);
            
        $len = strlen($this->email);
        if($len < ML_DATARULE_USER_EMAIL_MINLEN || $len > ML_DATARULE_USER_EMAIL_MAXLEN)
            $this->api_output(ML_RCODE_PARAM);
    }

}

new aj_sendEmailToReset();

